home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CICA 1993 April
/
CICA MS Windows - April 1993.iso
/
unzipped
/
programr
/
listings
/
blx12
/
pets.cpp
next >
Wrap
Text File
|
1991-05-02
|
649b
|
34 lines
// PETS.CPP : Conversations with your animals
#include <stdio.h>
struct pet {
virtual void speak() {} // function definition
};
struct dog : pet {
void speak() { puts("Bark!"); }
};
struct cat : pet {
void speak() { puts("Meow!"); }
};
struct bird : pet {
void speak() { puts("Tweet!"); }
};
struct goldfish : pet {
void speak() { puts("!"); }
};
// aggregate initialization of menagerie
pet* menagerie[] = { new dog, new cat, new bird };
const int sz = sizeof(menagerie)/sizeof(menagerie[0]);
void main(void)
{
for (int i = 0; i < sz; i++)
menagerie[i]->speak();
}